<template>
  
  <div class="home-singer">
    <van-search
      
      style="background-color: rgb(59, 59, 59);"
      v-model="search"
      placeholder="大家都在听"
      input-align="center"
      @search="onSearch"
    />
    <div class="wrapper" ref="wrapper">
      
      <ul class="content" ref="content">
        <li
          v-for="(item, index) in listData"
          :key="index"
          @click="selectItem(item)"
        >
          <div class="pic">
            <van-image :src="item.imageUrl" radius="10px" width="5rem" height="5rem" fit="contain"/>
            
          </div>
          <span>{{ item.title }}</span>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import { betterScrollHorizontal } from "../../common/betterScroll.js"; //引入betterscroll

export default {
  data() {
    return {
      listData: [
        {
          imageUrl: require('../../../images/boke.png'),
          title: '我的播客' 
        },
          {
          imageUrl: require('../../../images/fenlei.png'),
          title: '全部分类' 
        },
          {
          imageUrl: require('../../../images/top.png'),
          title: '排行榜' 
        },
          {
          imageUrl: require('../../../images/zhumian.png'),
          title: '助眠解压' 
        },
          {
          imageUrl: require('../../../images/youshengshu.png'),
          title: '有声书' 
        }
      ],
      listDatas: []
    };
  },
  created() {
    this.getSingerListData();
  },
  methods: {
    getSingerListData() {
      this.$request("get", "/singer/list").then((res) => {
        // console.log(res);
        if (res.result == 100) {
          this.listDatas = res.data.list.slice(0, 80);
        }
        // 异步数据的处理
        betterScrollHorizontal(
          this,
          this.$refs.wrapper,
          this.$refs.content,
          this.listData.length,
          10
        ); //调用横向滚动的方法
      });
    },
    selectItem(item) {
      const id = item.singer_mid;
      this.$router.push({
        path: `/singerhome/${id}`,
      });
    },
  },
};
</script>
<style scoped>
.wrapper {
  width: 100%; 
  overflow: hidden;
  text-align: left;
  
}

ul.content li {
  
  display: inline-block;
  
  width: 6rem;
  vertical-align: top;
  text-align: center;
   
}
ul.content li * {
 
  
  margin: 0.3rem;
}
ui.content li > img {
  width: 4rem;
  height: 4rem;
}
ul.content li > span {
  font-size: 1rem;
  color: rgb(99, 99, 99);
}
.home-singer > h1 {
  text-align: center;
  font-size: 22px;
  color: rgb(99, 99, 99);
}
</style>